import GlobalEvent from "../../Global/GlobalEvent";
import goldManager from "../goldManager";

//全局英雄攻击力购买管理器
class atkUp {
    private static instance: atkUp;
    private lv: number = 1;
    private addGold: number = 50;
    private addAtk: number = 5;
    private bool = true;

    private constructor() {
        //从服务器获取用户存储的lv值 更新lv


        //购买的金币 * 购买等级
        this.addGold = this.lv * 50;
        //购买的攻击力 * 购买等级
        this.addAtk *= this.lv;
    }

    public static getInstance(): atkUp {
        if (!atkUp.instance) {
            atkUp.instance = new atkUp();
        }
        return atkUp.instance;
    }
    public upLv() {
        this.lv++;
    }
    public getGold(): number {
        this.addGold = this.lv * 50;
        return this.addGold;
    }
    public getlv(): number {
        return this.lv;
    }
    public getAtk(): number {
        if (this.lv % 10 === 0) {
            this.addAtk = this.lv / 2;
            
        }
        
        return this.addAtk;
    }


    // 如果玩家的金币小于等于0或者小于所需金币，禁用按钮
    public getAtkbool() {
        let goldMana = goldManager.getInstance();
        // console.log('现在的金币 = ', goldMana.getGold());
        // console.log('购买所需的金币 = ', this.addGold);

        if (goldMana.getGold() <= 0 || goldMana.getGold() < this.addGold) {
            this.bool = false;
            GlobalEvent.emit('getAtkBoolean', this.bool)
            return;
        } else if (goldMana.getGold() >= this.addGold) {
            // 否则，激活按钮
            this.bool = true;
            GlobalEvent.emit('getAtkBoolean', this.bool)
            return;

        }

    }
}
export default atkUp;